﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Smartec.Accounts.Camel.AMS.Model.Entities;
using Smartec.Accounts.Camel.AMS.Model.Facades;



public class CustomAuthorizeAttribute : AuthorizeAttribute
{
    protected override bool AuthorizeCore(HttpContextBase httpContext)
    {
        if (httpContext == null)
            throw new ArgumentNullException("httpContext");

        //if (!httpContext.User.Identity.IsAuthenticated)
        //    return false;

        //var routeData = httpContext.Request.RequestContext.RouteData;
        //var controller = routeData.GetRequiredString("controller");
        //var action = routeData.GetRequiredString("action");
        string controller = httpContext.Request.Url.Segments.Count() < 2 ? "home" : httpContext.Request.Url.Segments[1].Trim('/');
        return AuthorizationManager.Authorize(controller, Action);
    }

    public string Action { get; set; }
}